home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 10 directories, files, and streams / dirfiledemo / classes.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  1.1 KB  |  45 lines

  1. ' two classes that extend  BinaryWriter and BinaryReader to support the Person object
  2.  
  3. Class BinaryWriterEx
  4.     Inherits System.IO.BinaryWriter
  5.  
  6.     Sub New(ByVal st As System.IO.Stream)
  7.         MyBase.New(st)
  8.     End Sub
  9.  
  10.     ' Add to the series of Write methods.
  11.     Overloads Sub Write(ByVal p As Person)
  12.         MyBase.Write(p.FirstName)
  13.         MyBase.Write(p.LastName)
  14.     End Sub
  15. End Class
  16.  
  17. Class BinaryReaderEx
  18.     Inherits System.IO.BinaryReader
  19.  
  20.     Sub New(ByVal st As System.IO.Stream)
  21.         MyBase.New(st)
  22.     End Sub
  23.  
  24.     ' A custom function that reads Person objects.    
  25.     Function ReadPerson() As Person
  26.         Dim FirstName As String = MyBase.ReadString()
  27.         Dim LastName As String = MyBase.ReadString()
  28.         ReadPerson = New Person(FirstName, LastName)
  29.     End Function
  30. End Class
  31.  
  32. ' the Person sample classes used by BinaryWriterEx and BinaryReaderEx
  33.  
  34. Class Person
  35.     Public FirstName As String
  36.     Public LastName As String
  37.  
  38.     Sub New(ByVal firstName As String, ByVal lastName As String)
  39.         Me.FirstName = firstName
  40.         Me.LastName = lastName
  41.     End Sub
  42. End Class
  43.  
  44.  
  45.